/**
 * 显示位置的元素
 */
define([
    'require',
    './Position'
], function(require, Position) {
    'use strict';
    /**
     * 在屏幕上显示的位置元素
     * @class
     * @param {*} viewer 
     * @param {*} top 
     * @param {*} left 
     */
    function PositionElement(viewer, parent, top, left){
        this._position = new Position(viewer,this._reRender.bind(this));
        this._parent = parent;
        this._element = document.createElement('div');
        this._top = top;
        this._left = left;
        this._components = new Array();
        this._init();
    }
    Object.defineProperties(PositionElement.prototype, {
        position : {
            get : function(){
                return this._position;
            }
        }
    })
    PositionElement.prototype._init = function(){   
        var position = this._position;
        var positionEle = this._element;

        this._parent.appendChild(this._element);
        positionEle.classList.add('position');
        /**
         * 相机位置    : x y z
         * 鼠标屏幕位置 : x y
         * 鼠标地理坐标 : x y z
         */
        var positionValues = [{
            t : '相机位置',
            v : [position.cameraPosition.x, position.cameraPosition.y, position.cameraPosition.z]
        },{
            t : '鼠标屏幕位置',
            v : [position.mousePositionOnScreen.x, position.mousePositionOnScreen.y]
        },{
            t : '鼠标地理坐标',
            v : [position.mousePositionOnWSG.x, position.mousePositionOnWSG.y, position.mousePositionOnWSG.z]
        }]
        // 构造元素
        var positionUl = document.createElement('ul');
        for(var i=0;i<positionValues.length;i++){
            var positionLi = document.createElement('li');
            var positionSpanT = document.createElement('span');
            positionSpanT.classList.add('position-t');
            positionSpanT.innerText = positionValues[i].t;
            var positionSpanV = document.createElement('span');
            positionSpanV.classList.add('position-v');
            for(var j=0;j<positionValues[i].v.length;j++){
                positionSpanV.innerText += positionValues[i].v[j]+', ';
            }
            positionLi.appendChild(positionSpanT);
            positionLi.appendChild(positionSpanV);
            positionUl.appendChild(positionLi);
            this._components.push(positionSpanV);
        }
        positionEle.appendChild(positionUl);
    }
    // 重绘
    PositionElement.prototype._reRender = function(){
        var components = this._components;
        var position = this._position;
        components[0].innerText = position.cameraPosition.x + ', ' + position.cameraPosition.y + ', ' + position.cameraPosition.z;
        components[1].innerText = position.mousePositionOnScreen.x + ', ' + position.mousePositionOnScreen.y;
        components[2].innerText = position.mousePositionOnWSG.x + ', ' + position.mousePositionOnWSG.y + ', ' + position.mousePositionOnWSG.z;
    }
    return PositionElement;
});